/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 */

package com.xci.edu.module.background.controller;

import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.core.BaseWebController;
import com.github.lvyanyang.core.BoolResult;
import com.github.lvyanyang.core.Const;
import com.github.lvyanyang.core.XCI;
import com.xci.edu.core.entity.EduStudentPeriodSummary;
import com.xci.edu.core.filter.EduStudentPeriodSummaryFilter;
import com.xci.edu.core.service.EduStudentPeriodSummaryService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 学员学时汇总页面控制器
 * @author 焦元义 jiaoyuanyi@xci96716.com
 * @since 2020-11-24 15:14:37
 */
@Authorize
@Controller
@RequestMapping(value = "/background/eduStudentPeriodSummary")
public class EduStudentPeriodSummaryController extends BaseWebController {
    /** 学员学时汇总服务 */
    @Resource private EduStudentPeriodSummaryService eduStudentPeriodSummaryService;

    //region 页面

    /** 首页 */
    @GetMapping
    @Authorize(code = "background.eduStudentPeriodSummary")
    public String index() {
        return "background/eduStudentPeriodSummary/index";
    }

//    /** 新建页 */
//    @GetMapping("/create")
//    //@Authorize(code = "core.eduStudentPeriodSummary.insert")
//    public String create(ModelMap map) {
//        createMark(map);
//        var entity = new EduStudentPeriodSummary();
//        entity.setId(XCI.nextId());
//        // entity.setStudentId();
//        // entity.setCoursewareId();
//        // entity.setPeriod();
//        map.put("entity", entity);
//        return "core/eduStudentPeriodSummary/edit";
//    }

//    /** 编辑页 */
//    @GetMapping("/edit")
//    //@Authorize(code = "core.eduStudentPeriodSummary.update")
//    public String edit(String id, ModelMap map) {
//        var entity = eduStudentPeriodSummaryService.selectById(Long.valueOf(id));
//        XCI.checkNotFoundData(entity, id);
//        map.put("entity", entity);
//        return "core/eduStudentPeriodSummary/edit";
//    }

//    /** 详情页 */
//    @GetMapping("/details")
//    public String details(String id, ModelMap map) {
//        var entity = eduStudentPeriodSummaryService.selectById(Long.valueOf(id));
//        XCI.checkNotFoundData(entity, id);
//        map.put("entity", entity);
//        return "core/eduStudentPeriodSummary/details";
//    }

    //endregion

    //region 处理

    /** 表格查询 */
    @ResponseBody
    @PostMapping("/grid")
    //@Authorize(code = "background.eduStudentPeriodSummary.select")
    public BoolResult grid(EduStudentPeriodSummaryFilter filter) {
        return BoolResult.success(eduStudentPeriodSummaryService.selectPageList(filter));
    }

    /** 新建保存 */
    @ResponseBody
    @PostMapping("/createSave")
    //@Authorize(code = "background.eduStudentPeriodSummary.insert")
    public BoolResult createSave(@ModelAttribute EduStudentPeriodSummary entity) {
        return eduStudentPeriodSummaryService.insert(entity);
    }

    /** 修改保存 */
    @ResponseBody
    @PostMapping("/updateSave")
    //@Authorize(code = "background.eduStudentPeriodSummary.update")
    public BoolResult updateSave(@ModelAttribute EduStudentPeriodSummary entity) {
        return eduStudentPeriodSummaryService.update(entity);
    }

//    /** 删除 */
//    @ResponseBody
//    @PostMapping("/delete")
//    //@Authorize(code = "core.eduStudentPeriodSummary.delete")
//    public BoolResult delete(String ids) {
//        return eduStudentPeriodSummaryService.delete(ids);
//    }

    /** 修改状态 */
    @ResponseBody
    @PostMapping("/status")
    @Authorize(code = "background.eduStudentPeriodSummary.updateStatus")
    public BoolResult status(String id, Integer status) {
        eduStudentPeriodSummaryService.updateStatus(id, XCI.toBool(status));
        return BoolResult.success();
    }

    /** 导出 */
    @GetMapping("/export")
    //@Authorize(code = "background.eduStudentPeriodSummary.export")
    public void export(EduStudentPeriodSummaryFilter filter) {
        XCI.exportExcel(eduStudentPeriodSummaryService.selectList(filter), EduStudentPeriodSummary.class, "学员学时汇总列表");
    }

    //endregion
}
